home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F27698_SortByAmount.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  4.2 KB  |  134 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ===========================================================
  3.   Category:       XSLT
  4.   Sub-category:   xsl:sort
  5.   Author:         David Silverlight
  6.                   HeadGeek@xmlpitstop.com
  7.   Created:        2001-05-16
  8.   Description:-
  9.     This stylesheet demonstrates the use of xsl:sort by
  10.     displaying employee information sorted by amount.
  11.  =============================================================== -->
  12. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  13.   <xsl:output method="html" />
  14.  
  15.   <xsl:template match="/">
  16.     <html>
  17.       <head>
  18.         <title>Stylesheet Example</title>
  19.         <style type="text/css"><![CDATA[
  20.         H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  21.         H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  22.         .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  23.         .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  24.         .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  25.         TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
  26.         TD {COLOR: darkblue; FONT-FAMILY: Arial}
  27.         TR { background-color: beige; }
  28.         BODY { background-color: beige; }
  29.         ]]></style>
  30.       </head>
  31.       <body>
  32.         <xsl:apply-templates />
  33.       </body>
  34.     </html>
  35.   </xsl:template>
  36.  
  37.   <xsl:template match="employees">
  38.     <h1>Sorting Employees by Hourly Rate in ascending order</h1>
  39.     <table border="1">
  40.       <tr>
  41.         <th>Name</th>
  42.         <th>Department</th>
  43.         <th>Hourly Rate</th>
  44.         <th>Start Date</th>
  45.         <th>Primary Language</th>
  46.       </tr>
  47.       <xsl:for-each select="employee">
  48.         <xsl:sort order="ascending" select="hourlyrate" data-type="number" />
  49.         <tr>
  50.           <td>
  51.             <xsl:value-of select="employeename" />
  52.           </td>
  53.           <td>
  54.             <xsl:value-of select="department" />
  55.           </td>
  56.           <td>
  57.             <xsl:value-of select="hourlyrate" />
  58.           </td>
  59.           <td>
  60.             <xsl:value-of select="startdate" />
  61.           </td>
  62.           <td>
  63.             <xsl:value-of select="primarylanguage" />
  64.           </td>
  65.         </tr>
  66.       </xsl:for-each>
  67.     </table>
  68.     <br />
  69.     <br />
  70.     <h1>Sorting Employees by HourlyRate in descending order</h1>
  71.     <table border="1">
  72.       <tr>
  73.         <th>Name</th>
  74.         <th>Department</th>
  75.         <th>Hourly Rate</th>
  76.         <th>Start Date</th>
  77.         <th>Primary Language</th>
  78.       </tr>
  79.       <xsl:for-each select="employee">
  80.         <xsl:sort order="descending" select="hourlyrate" data-type="number" />
  81.         <tr>
  82.           <td>
  83.             <xsl:value-of select="employeename" />
  84.           </td>
  85.           <td>
  86.             <xsl:value-of select="department" />
  87.           </td>
  88.           <td>
  89.             <xsl:value-of select="hourlyrate" />
  90.           </td>
  91.           <td>
  92.             <xsl:value-of select="startdate" />
  93.           </td>
  94.           <td>
  95.             <xsl:value-of select="primarylanguage" />
  96.           </td>
  97.         </tr>
  98.       </xsl:for-each>
  99.     </table>
  100.     <br />
  101.     <h1>Incorrect Sorting of Employees by HourlyRate</h1>
  102.     <span class="subhead">This example demonstrates the how omitting the data-type attribute will cause your numbers to be sorted alphabetically, rather than by their numeric value (yes, this is bad)</span>
  103.     <br />
  104.     <table border="1">
  105.       <tr>
  106.         <th>Name</th>
  107.         <th>Department</th>
  108.         <th>Hourly Rate</th>
  109.         <th>Start Date</th>
  110.         <th>Primary Language</th>
  111.       </tr>
  112.       <xsl:for-each select="employee">
  113.         <xsl:sort order="ascending" select="hourlyrate" />
  114.         <tr>
  115.           <td>
  116.             <xsl:value-of select="employeename" />
  117.           </td>
  118.           <td>
  119.             <xsl:value-of select="department" />
  120.           </td>
  121.           <td>
  122.             <xsl:value-of select="hourlyrate" />
  123.           </td>
  124.           <td>
  125.             <xsl:value-of select="startdate" />
  126.           </td>
  127.           <td>
  128.             <xsl:value-of select="primarylanguage" />
  129.           </td>
  130.         </tr>
  131.       </xsl:for-each>
  132.     </table>
  133.   </xsl:template>
  134. </xsl:stylesheet>